/*************************************************************************
	> File Name: process.c
	> Author: 茉莉玫瑰花茶
	> Mail: 19835250658@163.com
	> Created Time: Sun 06 Jul 2025 09:39:06 PM CST
 ************************************************************************/

#include "process.h"

#define NUM 101
#define STYLE '='

void process_v1()
{
	// printf("hello Linux!\n");
	char buffer[NUM];
	memset(buffer, 0, sizeof(buffer));
	const char *lable = "|/-\\";
	size_t len = strlen(lable);

	int cnt = 0;
	while (cnt <= 100)
	{
		printf("[%-100s][%d%%][%c]\r", buffer, cnt, lable[cnt % len]);
		fflush(stdout);
		buffer[cnt] = STYLE;
		cnt++;
		usleep(10000);
	}
	printf("\n");
	return;
}

void FlushProcess(double total, double current)
{
	char buffer[NUM];
	memset(buffer, 0, sizeof(buffer));
	const char *lable = "|/-\\";
	size_t len = strlen(lable);

	static int cnt = 0;

	// 计算当前进度条的填充数量
	int num = (int)(current * 100 / total);
	for (int i = 0; i < num; ++i)
	{
		buffer[i] = STYLE;
	}
	double rate = current / total * 100;
	cnt %= len;
	printf("[%-100s][%.1f%%][%c]\r", buffer, rate, lable[cnt]);
	++cnt;
	// fflush(stdout);
}
